package com.xdf.zipperdye.controller;

import com.xdf.zipperdye.model.BillOrder;
import com.xdf.zipperdye.service.BillOrderService;
import com.xdf.zipperdye.utils.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(description = "客户订单")
@CrossOrigin
@RestController
@RequestMapping("/billOrder")
public class BillOrderController {
    @Autowired
    private BillOrderService service;

    @ApiOperation(value="新增", notes="测试数据：http://localhost:7075/zipperdye/billOrder/insert\n" +
            "{\"main\":{\"bill_date\":\"2022-04-21 00:00:00\",\"client_sid\":\"1001\"},\"details\":[{\"product_sid\":\"珊瑚绒\",\"color\":\"红色\",\"amount\":\"10\",\"kilo\":\"3596.3\"}]}", produces="application/json")
    @PostMapping("/insert")
    public JsonResult insert(@RequestBody BillOrder record){
        return JsonResult.ok(service.insert(record));
    }

    @ApiOperation(value="删除", notes="删除", produces="application/json")
    @GetMapping("/delete/{iid}")
    public JsonResult delete(@PathVariable Integer iid){
        return JsonResult.ok(service.deleteByPrimaryKey(iid));
    }

    @ApiOperation(value="修改", notes="测试数据：{\"main\":{\"iid\":3,\"bill_date\":\"2022-04-21 00:00:00\",\"client_sid\":\"1001\"},\"details\":[{\"iid\":3,\"parent_id\":3,\"product_sid\":\"珊瑚绒1\",\"color\":\"红色\",\"amount\":\"11\",\"kilo\":\"3596.3\"}]}", produces="application/json")
    @PostMapping("/update")
    public JsonResult update(@RequestBody BillOrder record){
        return JsonResult.ok(service.update(record));
    }

    @ApiOperation(value="根据主键查询", notes="测试请求：http://localhost:7075/zipperdye/billOrder/selectByPrimaryKey/3", produces="application/json")
    @GetMapping("/selectByPrimaryKey/{iid}")
    public JsonResult selectByPrimaryKey(@PathVariable Integer iid){
        return JsonResult.ok(service.selectByPrimaryKey(iid));
    }

    @ApiOperation(value="根据单据编号查询", notes="测试请求：http://localhost:7075/zipperdye/billOrder/selectByBillcode/OD220408001", produces="application/json")
    @GetMapping("/selectByBillcode/{billCode}")
    public JsonResult selectByBillcode(@PathVariable String billCode){
        return JsonResult.ok(service.selectByBillCode(billCode));
    }

}
